package com.xiaochen.service.config;

import com.xiaochen.service.interceptor.UserLoginAuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 用户认证配置类
 */
@Configuration
public class UserAuthConfig implements WebMvcConfigurer {

    @Bean
    public UserLoginAuthInterceptor userLoginAuthInterceptor() {
        return new UserLoginAuthInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userLoginAuthInterceptor())
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/user/login", "/api/user/register");
    }
}